package com.eies.business.dataprocess.adpter;

import java.util.ResourceBundle;

import com.eies.business.dataprocess.adpter.remote.bean.ResponseMsgBean;
import com.eies.common.LogWritter;



/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: 2013</p>
 * <p>Company: DigitalChina</p>
 * @author jiamj
 * @date 2013-4-19
 * @version 1.0
 */
public class DoServiceImpl {
	private volatile ResponseMsgBean rtnMsgBean;
	private String serviceId;
	private String xml;
	
	public DoServiceImpl(){
		
	}
	public class threadTimeout extends Thread{

		public void run(){   
			LogWritter.info("start of threadtime",threadTimeout.class);
			try{
				rtnMsgBean=doThreadService(serviceId, xml);
				
			}catch (Exception e){
				LogWritter.error("",e,"");
			}
			LogWritter.info("end of threadtimeout.run",threadTimeout.class);
		}

		public threadTimeout(){
		}
	}
	public ResponseMsgBean doService(String serviceId, String xml)throws Exception {
		this.serviceId =serviceId;
		this.xml = xml;
		
		Thread runit = new threadTimeout();
		runit.start();
		try{
			ResourceBundle rb = ResourceBundle.getBundle("esb");
			String strTimeOut =strTimeOut = new String(rb.getString("EsbTimeOut"));
			runit.join(Integer.valueOf(strTimeOut));
			if (runit.isAlive()){
				runit.interrupt();
			}
		}
		catch (Exception e){
			LogWritter.error("",e,"");
			throw new Exception(e);
		}
		return rtnMsgBean; 
	}
	
	private ResponseMsgBean doThreadService(String serviceId, String xml)throws Exception{
		ResponseMsgBean rmb = EsbAdapter.doService(serviceId, xml);
		return rmb;
	}
}
